import { Button, Card, List, NavBar, Toast } from "antd-mobile";
//@ts-ignore
import { useNavigate } from "umi";
import React, { useEffect, useState } from "react";
import axios from "axios";

function index() {
  const navigate = useNavigate();
  const back = () => navigate("/user");
  //  全部的订单信息
  const [ordersList, setOrdersList] = useState<any>();
  //   查询全部订单
  const allOrder = async () => {
    const res = await axios({
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        token: localStorage.getItem("token"),
      },
      method: "get",
      url: `http://43.139.124.13:8888/order/getMyOrderList`,
    });
    setOrdersList(res.data.data);
    console.log(res);
  };
  //   //   通过id获取商品信息
  //   const getProductById = async () => {
  //     const res = await axios({
  //         headers: {
  //           "Content-Type": "application/x-www-form-urlencoded",
  //           token: localStorage.getItem("token"),
  //         },
  //         method: "get",
  //         url: `http://43.139.124.13:8888/product/getById/${id}`,
  //       });
  //   };

  useEffect(() => {
    allOrder();
  }, []);

  return (
    <>
      <NavBar onBack={back}>订单列表</NavBar>
      {/* 我的订单 */}
      {/* {JSON.stringify(ordersList)} */}
      {ordersList?.map((item: any) => (
        <List key={item.id}>
          <List.Item
            title={`订单编号:${item.orderNo} `}
            description={`地址：${item.linkAddress}`}
            clickable
          >
            {`总价${item.totalPrice}`}
            <br />
            <span style={{ fontSize: 8 }}>手机号：{item.linkPhone}</span>
          </List.Item>
        </List>
      ))}
    </>
  );
}

export default index;
